package vip.xiaonuo.modular.model;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Scanner;

import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
public class PoiTest {
    public static void main(String[] args) throws Exception {
        // 创建文档对象
        XWPFDocument document = new XWPFDocument();

        // Create a paragraph with an image
        XWPFParagraph paragraph = document.createParagraph();
        XWPFRun run = paragraph.createRun();
        run.setText("考生唯一条形码");
        run.addBreak();
        String imagePath = "D:/IdeaProjects/snowy-layui-origin/"+ "" +".png";
        int imageFormat = XWPFDocument.PICTURE_TYPE_PNG;
        FileInputStream inputStream = new FileInputStream(imagePath);
        run.addPicture(inputStream, imageFormat, imagePath, 3000000, 1000000);

        // 创建表格对象，并设置表格的列数和行数
        XWPFTable table = document.createTable(4, 2);

        // 循环遍历表格的每
        for (int i = 0; i < 4; i++) {
            XWPFTableRow row = table.getRow(i);
            row.getCell(0).setText(getLabelText(i)); // 设置标签文本
            row.getCell(1).setText(getInputText()); // 获取用户输入并设置为单元格文本
        }

        // 创建段落对象，并为其添加文本内容
        XWPFParagraph paragraph2 = document.createParagraph();
        XWPFRun run2 = paragraph2.createRun();
        run2.setText("以上信息填写正确后，请务必保存本文档并发送至相关邮箱。");

        // 保存文档到文件
        FileOutputStream out = new FileOutputStream("考试报名表.docx");
        document.write(out);
        out.close();

        System.out.println("考试报名表生成完毕。");
    }

    // 获取标签文本
    private static String getLabelText(int index) {
        switch (index) {
            case 0:
                return "姓名：";
            case 1:
                return "性别：";
            case 2:
                return "身份证号：";
            case 3:
                return "联系电话：";
            default:
                return "";
        }
    }

    // 获取用户输入
    private static String getInputText() {
        Scanner scanner = new Scanner(System.in);
        return scanner.nextLine();
    }
}


